<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  
    <title>操作员权限分配</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="<s:url value="/css/common.css"/>" type="text/css"	rel="stylesheet" />
	
	<script type="text/javascript" src="<c:url value="/js/jquery-1.3.2.js" />"></script>   
	<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
	<script language="javascript" type="text/javascript" src="<c:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
  
	<style type="text/css">
  
		.tb_h3 {
		  color: #000;
		  height: 22px;
		  line-height: 22px;
		  font-size: 12px;
		  font-family: "Microsoft YaHei", Arial, sans-serif;
		  padding: 0 5px;
		  font-weight: 700;
		}
	</style>
  <script type="text/javascript">
  

function goback(){
  	history.go(-1);
  }
function selectAllEvent(objCheckbox){
	 	var tempObj=$(objCheckbox);
	 	if(tempObj.attr('checked')){
	 		var tableId=tempObj.attr('name');
	    	$('#'+tableId).find(":checkbox[name=userModuleRightCodeList]").each(function(){
	   		 	$(this).attr('checked',true);
	 	 	}); 
	 	}else{
	 		var tableId=tempObj.attr('name');
	    	$('#'+tableId).find(":checkbox[name=userModuleRightCodeList]").each(function(){
	   		 	$(this).attr('checked',false);
	 	 	}); 
	 	}
	}

$(document).ready(function(){
    $("#backBtn").click(function(){
       self.history.back(1);
       return false;
    });
    
    $("#setBtn").click(function(){
       //$("#athourityForm").attr("action","/powers/editMerchantPowerYJ.ct");
       var accountNo=$("#accountNo").val();
       var checkList="";
       $('[name=userModuleRightCodeList]:checkbox:checked').each(function(){
            checkList+=$(this).val()+",";
       });
       window.location.href="<%=basePath%>powers/editMerchantAnalyPowerYJ.ct?checkList="+checkList+"&merchant.accountNo="+accountNo+"";
       return false;     
    });
    
	$(":input[name=athorityValue]").each(function(){
	 	var aVal=$(this).val();
	 	$(":checkbox[name=userModuleRightCodeList]").each(function(){
	 		var moduleval=$(this).val();
	 		if(aVal==moduleval){
	 			$(this).attr('checked',true);
	 		}
	 	});
	 	
	 });
	$(":checkbox[name=userModuleRightCodeList]").each(function(){
		  var tableId=$(this).closest("table").attr('id');
		  var checkedNumber=$('#'+tableId).find(":checkbox[name=userModuleRightCodeList]:checked").length;
		  var totalNumber=$('#'+tableId).find(":checkbox[name=userModuleRightCodeList]").length;
		  var checkAllObj=$('#'+tableId).closest("tr").prev().find(":checkbox[name="+tableId+"]");
		  if(checkedNumber==totalNumber){
			  checkAllObj.attr('checked',true);
		  }else{
			  checkAllObj.attr('checked',false);
		  }
		  $(this).click(function(){
			  checkedNumber=$('#'+tableId).find(":checkbox[name=userModuleRightCodeList]:checked").length;
			    if(checkedNumber==totalNumber){
			    	checkAllObj.attr('checked',true);
			    }else{
			    	checkAllObj.attr('checked',false);
			    }
		  });
		 var tdObj=$(this).closest('td');
		 tdObj.find('label').click(function(){		
			 tdObj.find(":checkbox[name=userModuleRightCodeList]").each(function(){
					if($(this).attr('checked')){
						$(this).attr('checked',false);
					}else{
						$(this).attr('checked',true);
					}
					checkedNumber=$('#'+tableId).find(":checkbox[name=userModuleRightCodeList]:checked").length;
					if(checkedNumber==totalNumber){
						  checkAllObj.attr('checked',true);
					 }else{
						 checkAllObj.attr('checked',false);
					 }
			 });
		 });
	 });
	 
	 
	 
 
});

</script>
  </head>
  
  <body>
    <!-- <div align="center" style="width:100%"><h1>优化中</h1></div> -->
   
  
   	<s:form id="athourityForm" action="/athourity/setAthourity.action" method="post"  theme="simple">
    	<s:hidden name="merchant.id"></s:hidden>
     
	<table width="100%" class="tb" >
		<tr class="tb-line">
			<td class="tb-td" colspan="6">
				<div class="tb-h2">POS收单运营管理平台</div>
			</td>
		</tr>
		<tr class="tb-line bg-gray">
			<td class="tb-td" colspan="4"><div class="tb-h3">操作员权限信息</div></td>
		</tr>
		<tr class="tb-line">
			<td align="right" class="tb-td" style="width:110px;">
				<div class="tb-h4">账号：</div>
			</td>
			<td class="tb-td" >
				<label class="tb-input-lengthen">
					<s:property value="#request.merchant.accountNo" />
				</label>
			</td>
			<td align="right" class="tb-td" style="width:110px;">
				<div class="tb-h4">姓名：</div>
			</td>
			<td class="tb-td" >
				<label class="tb-input-lengthen">
					<s:property value="#request.merchant.realName" />
				</label>
			</td>
		</tr>
		<tr class="tb-line">
			<td align="right" class="tb-td" style="width:110px;">
				<div class="tb-h4">证件号：</div>
			</td>
			<td class="tb-td" >
				<label class="tb-input-lengthen">
					<s:property value="#request.merchant.cardNo" />
				</label>
			</td>
			<td align="right" class="tb-td" style="width:110px;">
				<div class="tb-h4">手机号：</div>
			</td>
			<td class="tb-td" >
				<label class="tb-input-lengthen">
					<s:property value="#request.merchant.mobile" />
				</label>
			</td>
		</tr>
		<tr class="tb-line">
			<td align="right" class="tb-td" style="width:110px;">
				<div class="tb-h4">角色类别：</div>
			</td>
			<td class="tb-td" >
				<label class="tb-input-lengthen">
					<s:property value="#request.merchant.roleName" />
				</label>
			</td>
			<td align="right" class="tb-td" style="width:110px;">
				<div class="tb-h4">状态：</div>
			</td>
			<td class="tb-td" >
				<label class="tb-input-lengthen">
					<s:property value="#request.merchant.statusDesc" />
				</label>
			</td>
		</tr>
	</table>
	<br/>
    <div  style="overflow-y:auto;overflow-x:hidden;width:100%;height:500px; ">
	<s:if test="#request.moduleList!=null&&#request.moduleList.size>0">
    	<s:iterator value="#request.moduleList" status="stat" id="bean">
    		<s:hidden name="athorityValue" value="%{#bean.moduleCode}"></s:hidden>
		</s:iterator>
	</s:if> 
	<table id="userRight" width="100%" class="tb" >
	<tbody>
		<s:iterator value="#request.moduleCateList" status="stat" id="element">
		
		<tr class="tb-line bg-gray">
			<td  align="left" class="tb-td tb_h3"  colspan="2">
					<s:property value="#element.moduleCategoryName"/>
					<s:checkboxlist list="#{#element.moduleCategoryCode:''}" name="%{#element.moduleCategoryCode}"   
						cssClass="checkbox" onclick="selectAllEvent(this)"/>
			</td>
		</tr>
		<tr class="tb-line">
			<td colspan="2">
				<table id="${element.moduleCategoryCode}" width="100%" border="0" cellpadding="0" cellspacing="1">
					<tbody>
						<tr> 
							<td width="20" >&nbsp;</td> 
							<s:iterator value="#element.modules" status="st" id="module">
								<td width="140" class="label tb-h4">
									<s:checkboxlist name="userModuleRightCodeList" list="#{#module.moduleCode:''}" cssClass="checkbox"></s:checkboxlist>
									<label><s:property value="#module.moduleName"/></label>
								</td>
							</s:iterator>
			 				<td>&nbsp;</td> 
						</tr>
					</tbody>
				</table>
			</td>
		</tr>
	</s:iterator>
	<s:hidden name="accountNo" id="accountNo" value="%{#request.accountNo}"/>
		<tr class="tb-line">
			<td class="tb-td line-submit" align="center" colspan="4">
				<label class="tb-input-submit">
					<s:submit  id="setBtn" value="保  存" ></s:submit>
				</label>
				<label class="tb-input-submit">
					<s:submit id="backBtn" value="返  回" ></s:submit>
				</label>
			</td>
		</tr>
	</tbody>
</table>
   
</div>
</s:form>
    
  </body>
</html>
